package com.missfresh.cooperation2meituan.util;

import java.util.Collections;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SignUtil {
	
	private static String CONSUMER_SECRET;
	
	private static final Logger logger = LoggerFactory.getLogger(SignUtil.class);
	
	public static void dicSort(List<String> params) {
		Collections.sort(params);
	}

	public static String listToString(List<String> list, String separator) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < list.size(); i++) {
			sb.append(list.get(i)).append(separator);
		}
		return sb.toString().substring(0, sb.toString().length() - 1);
	}
	
	public static String createSign(List<String> list,String url){
		Collections.sort(list);
		String params = listToString(list,"&");
		String sig = url+"?"+params+CONSUMER_SECRET;
		logger.info("签名前"+sig);
		logger.info("签名后"+MD5Util.MD5(sig));
		return MD5Util.MD5(sig);
	}

	public static String getCONSUMER_SECRET() {
		return CONSUMER_SECRET;
	}

	public static void setCONSUMER_SECRET(String cONSUMER_SECRET) {
		CONSUMER_SECRET = cONSUMER_SECRET;
	}

}
